/**
 * Created by zyy on 15/5/5.
 * zhangyuyu@superjia.com
 */
(function ($) {
    var sendAction = {

        __container: null,
        __options: null,

        init: function (container, options) {
            var self = this
            self.__container = container
            self.__options = options

            container.html(tpl)

            self.__bindEvent()
        },

        __bindEvent: function () {
            var self = this
            var container = self.__container
            var fileItems = self.__options.fileItems
            var panel = container.find('.mod-send')
            panel.on('click', '.back', function () {
                $.jps.publish('action-back')
            })

            var sendInput = panel.find('.send-input')

            panel.on('click', '.opt-btn', function () {
                var email = $.trim(sendInput.val())

                /*if (!email || !App.common.modules.util.isEmail(email)) {
                    App.common.modules.smallnote('请输入正确的电邮地址', {
                        pattern: 'error'
                    })
                    sendInput.focus()
                    return false
                } else {*/
                    $.ajax({
                        url: '/review/file/sendfile4cjt/',
                        method: 'post',
                        dataType: 'json',
                        data: {
                            email: email,
                            path: _.map(fileItems, function(item) {
                                return item.get('path')
                            })
                        },
                        traditional: true,
                        success: function (data) {
                            if(data.code == 0){
                                App.common.modules.smallnote('恭喜您，发送成功')
                                $.jps.publish('action-back')
                            }
                        }
                    })
                //}
            })
        }
    }

    var tpl = '' +
        '<div class="mod-send">' +
        '   <div class="action-header">' +
        '       <a class="back">&lt;</a><div class="title">发送</div><div class="opt-btn">发送</div>' +
        '   </div>' +
        '   <div class="send-wrap">' +
        '       <input class="send-input" placeholder="请输入账号" />' +
        '   </div>' +
        '</div>'

    App.modules.sendAction = sendAction
})(jQuery)
